package com.af.community.smart.business

import android.graphics.Color
import android.os.Bundle
import android.view.View
import android.widget.TextView
import com.af.community.smart.base.BaseActivity
import com.af.community.smart.base.getColorEx
import com.af.community.smart.base.loadLinear
import com.af.community.smart.model.ResultData
import com.af.community.smart.utils.NormalDecoration
import com.af.community.smart.utils.dp2px
import com.af.community.smart.utils.sp2px
import kotlinx.android.synthetic.main.layout_list.*
import net.idik.lib.slimadapter.SlimAdapter
import org.jetbrains.anko.include

class HandleTaxResultActivity : BaseActivity() {

    private val list = ArrayList<ResultData>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        include<View>(R.layout.layout_list)
        initTitle(title = "查询结果")

        list.apply {
            add(ResultData("纳税人识别号：", "12100000144422001530", "登记信息"))
            add(ResultData("纳税人名称：", "明湖社区", "登记信息"))
            add(ResultData("登记注册类型：", "事业单位", "登记信息"))
            add(ResultData("法定代表人：", "林芝", "登记信息"))
            add(ResultData("注册地址：", "明湖路123号", "登记信息"))
            add(ResultData("生产经营地址：", "明湖路123号", "登记信息"))
            add(ResultData("主管税务机关：", "明湖税务分局", "登记信息"))
            add(ResultData("税务管理员：", "放一", "登记信息"))
            add(ResultData("纳税人税务登记状态：", "正常", "登记信息"))
            add(ResultData("一般纳税人自个状态：", "增值税一般纳税人", "登记信息"))
            add(ResultData("一般纳税人资格登记时间：", "2016-06-23", "登记信息"))
            add(ResultData("出口状态设备状态：", "", "登记信息"))
            add(ResultData("是否按季申报：", "月", "登记信息"))
            add(ResultData("纳税信用等级：", "", "登记信息"))
            add(ResultData("", "", "非正常户信息"))
            add(ResultData("", "", "未申报及欠税信息"))
            add(ResultData("", "", "丢失被盗发票信息"))
            add(ResultData("", "", "重大违法信息"))
        }
        mAdapter.updateData(list)
    }

    override fun initTitle(title: String, name: String) {
        super.initTitle(title, name)
        swipe_refresh.isEnabled = false
        recycle_list.apply {
            loadLinear(baseContext)

            addItemDecoration(object : NormalDecoration() {
                override fun getHeaderName(pos: Int): String = list[pos].letter
            }.apply {
                setHeaderContentColor(getColorEx(R.color.header))
                setHeaderHeight(dp2px(50f))
                setTextSize(sp2px(14f))
                setTextColor(Color.parseColor("#464F6F"))
                setTextPaddingLeft(dp2px(15f))
            })
        }

        mAdapter = SlimAdapter.create()
            .register<ResultData>(R.layout.item_tax_list) { data, injector ->

                val index = list.indexOf(data)
                val isLast = index == list.size - 1

                injector.text(R.id.item_tax_left, if (data.title.isEmpty()) "没有相关信息" else data.title)
                    .text(R.id.item_tax_right, data.content)
                    .with<TextView>(R.id.item_tax_left) {
                        val blueLight = baseContext.getColorEx(R.color.blue_light)
                        val blueDark = baseContext.getColorEx(R.color.blue_dark)
                        it.setTextColor(if (data.title.isEmpty()) blueLight else blueDark)
                    }
                    .visibility(
                        R.id.item_tax_divider,
                        if ((!isLast && data.letter != list[index + 1].letter) || isLast) View.VISIBLE else View.GONE
                    )
            }
            .attachTo(recycle_list)
    }

}
